<?php

namespace app\admin\controller\shopro\order;

use app\common\controller\Backend;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
use Exception;
use app\admin\model\shopro\Information as InformationModel;
use app\admin\controller\shopro\Base;
/**
 * 宿舍号管理
 *
 * @icon fa fa-users
 */
class Floor extends Base
{

    /**
     * @var \app\admin\model\UserGroup
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\shopro\order\Order;
    }
     /**
     * 查看
     */
    public function index()
    {
        //当前是否为关联查询
        $this->relationSearch = false;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax())
        {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField'))
            {
                return $this->selectpage();
            }
            $where_other = [];
            $where_other['floor'] = array("<>","");
            $nobuildfields = ['floor'];
            list($where, $sort, $order, $offset, $limit) = $this->custombuildparams(null, $nobuildfields);
            $filter = json_decode($this->request->get("filter", ''), true);
            if(isset($filter['floor']) && $filter['floor']){
                $where_other['floor|room'] = array("like","%".$filter['floor']."%");
            }
            $total = $this->model
                    ->where($where)
                    ->where($where_other)
                    ->order($sort, $order)
                    ->count();

            $list = $this->model
                    ->where($where)
                    ->where($where_other)
                    ->order($sort, $order)
                    ->limit($offset, $limit)
                    ->select();
            $list = collection($list)->toArray();
            $result = array("total" => $total, "rows" => $list);
            return $result;
        }
        return $this->view->fetch();
    }
}
